package com.roamer.util;

/**
 * 断言类
 *
 * @author roamer
 * @version V1.0
 * @date 2019/1/20 15:21
 */
public abstract class Assert {

    /**
     * Assert that an object is null
     *
     * @param object  需检查的对象
     * @param message 错误提示
     */
    public static void isNull(Object object, String message) {
        if (object != null) {
            throw new IllegalArgumentException(message);
        }
    }

    /**
     * Assert that an object is not null
     *
     * @param object  需检查的对象
     * @param message 错误提示
     */
    public static void isNotNull(Object object, String message) {
        if (object == null) {
            throw new IllegalArgumentException(message);
        }
    }

    /**
     * Assert that an CharSequence is not null and length > 0
     *
     * @param cs      需检查的字符串
     * @param message 错误提示
     */
    public static void hasLength(CharSequence cs, String message) {
        if (!StringUtils.hasLength(cs)) {
            throw new IllegalArgumentException(message);
        }
    }

    /**
     * Assert that an CharSequence is not empty and not null and not whitespace only
     *
     * @param cs      需检查的字符串
     * @param message 错误提示
     */
    public static void hasText(CharSequence cs, String message) {
        if (!StringUtils.hasText(cs)) {
            throw new IllegalArgumentException(message);
        }
    }
}
